package com.wzcl.app.dao.repository;

import com.wzcl.app.dao.model.TopUpOrder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

public interface TopUpOrderRepository extends JpaRepository<TopUpOrder, Integer>, JpaSpecificationExecutor {

    //根据订单号查询消费的学币
    @Query(value = "select c.money from TopUpOrder c where c.orderNumber = ?1")
    Double findLearnCoin(String orderNumber);

    //充值成功根据订单号更新订单信息
    @Query(value = "update TopUpOrder c set c.payState = ?1, c.orderState = ?2 where c.orderNumber = ?3")
    @Transactional
    @Modifying
    void updatePayStateByOrderNumber(Integer payState, Integer orderState, String orderNumber);

    //通过订单号查询订单id
    @Query(value = "select c.id from TopUpOrder c where c.orderNumber = ?1")
    Integer findOrderIdByOrderNumber(String orderNumber);

    //通过订单号查找课程订单
    TopUpOrder findAllByOrderNumber(String orderNumber);
}
